package com.iceberg.action.customer;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import com.iceberg.model.customer.Customer;
import com.iceberg.service.customer.CustomerService;
import com.opensymphony.xwork2.ModelDriven;

public class CustomerAction implements ModelDriven {

  Customer customer = new Customer();
  List<Customer> customerList = new ArrayList<Customer>();

  CustomerService customerService;

  public void setCustomerService(CustomerService customerBo) {
    this.customerService = customerBo;
  }

  public Object getModel() {
    return customer;
  }

  public List<Customer> getCustomerList() {
    return customerList;
  }

  public void setCustomerList(List<Customer> customerList) {
    this.customerList = customerList;
  }

  //save customer
  public String addCustomer() throws Exception {

    //save it
    customer.setCreatedDate(new Date());
    customerService.addCustomer(customer);

    //reload the customer list
    customerList = null;
    customerList = customerService.listCustomer();

    return "success";

  }

  //list all customers
  public String listCustomer() throws Exception {

    customerList = customerService.listCustomer();

    return "success";

  }

}
